package cn.lili.controller.feign.system;

import cn.lili.common.enums.SwitchEnum;
import cn.lili.modules.system.client.LogisticsClient;
import cn.lili.modules.system.entity.dos.Logistics;
import cn.lili.modules.system.entity.vo.Traces;
import cn.lili.modules.system.service.LogisticsService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 物流 feign client
 *
 * @author Chopper
 * @version v1.0
 * 2021-12-07 19:23
 */
@RestController
@RequiredArgsConstructor
public class LogisticsFeignController implements LogisticsClient {
    private final LogisticsService logisticsService;

    @Override
    public List<Logistics> list() {
        return logisticsService.list();
    }

    @Override
    public Logistics getById(String logisticsId) {
        return logisticsService.getById(logisticsId);
    }

    @Override
    public Traces getLogistic(String mLogisticsCode, String mLogisticsNo, String customerName) {
        return logisticsService.getLogistic(mLogisticsCode, mLogisticsNo, customerName);
    }

    @Override
    public Logistics getByName(String name) {
        LambdaQueryWrapper<Logistics> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(Logistics::getName, name);
        lambdaQueryWrapper.eq(Logistics::getDisabled, SwitchEnum.OPEN.name());
        lambdaQueryWrapper.last("limit 1");
        return logisticsService.getOne(lambdaQueryWrapper);
    }

    @Override
    public String save(Logistics logistics) {
        logisticsService.getBaseMapper().insert(logistics);
        return logistics.getId();
    }
}
